//
//  CLDeviceInfo.m
//  toroBracelet
//
//  Created by 丁益 on 16/7/26.
//  Copyright © 2016年 celi. All rights reserved.
//  

#import "CLDeviceInfo.h"
#import "CLSeverTool.h"

@implementation CLDeviceInfo

SingletonM(DeviceInfo)


- (NSString *)deviceId{
    
    if (_deviceId == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"deviceId"] == nil) {
            return @"20161212001";
        }
        return [dict objectForKey:@"deviceId"];
    }
    return _deviceVersion;
}

- (BOOL) setDeviceIdAndCache:(NSString *)deviceId{
    _deviceId = deviceId;
    
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:_deviceVersion forKey:@"deviceId"];
    return [dict writeToFile:filePath atomically:YES];
    
}

- (NSString *)deviceVersion{

//    return @"目前手环版本(1000)";
    if (_deviceVersion == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"deviceVersion"] == nil) {
            return @"获取失败";
        }
        return [dict objectForKey:@"deviceVersion"];
    }
    return _deviceVersion;
}

- (BOOL) setDeviceVersionAndCache:(NSString *)deviceVersion{
    
    _deviceVersion = deviceVersion;
    
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:_deviceVersion forKey:@"deviceVersion"];
    return [dict writeToFile:filePath atomically:YES];
}



- (NSArray *)alarmClockArray{
    
    if (_alarmClockArray == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"alarmClockArray"] == nil) {
            return nil;
        }
        return [dict objectForKey:@"alarmClockArray"];
    }
    return _alarmClockArray;
}

- (BOOL)setAlarmClockAndCache:(NSArray *)alarmClockArray{
    
    _alarmClockArray = alarmClockArray;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:alarmClockArray forKey:@"alarmClockArray"];
    return [dict writeToFile:filePath atomically:YES];
}


- (NSString *)bandType {
    
    if (_bandType == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"bandType"] == nil) {
            return @"未知设备";
        }
        return [dict objectForKey:@"bandType"];
    }
    return _deviceVersion;
}

- (BOOL)setBandTypeAndCache:(NSString *)bandType{

    _bandType = bandType;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:bandType forKey:@"bandType"];
    return [dict writeToFile:filePath atomically:YES];
}


- (NSString *)careNumberId {

    if (_careNumberId == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"careNumberId"] == nil) {
            return nil;
        }
        return [dict objectForKey:@"careNumberId"];
    }
    return _careNumberId;
}

- (BOOL)setCareNumberIdAndCache:(NSString *)careNumberId{

    _careNumberId = careNumberId;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:careNumberId forKey:@"careNumberId"];
    return [dict writeToFile:filePath atomically:YES];
}

- (NSString *)careMoney {

    if (_careMoney == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"careMoney"] == nil) {
            return nil;
        }
        return [dict objectForKey:@"careMoney"];
    }
    return _careMoney;
    
}

- (BOOL)setCareMoneyAndCache:(NSString *)careMoney {

    _careMoney = careMoney;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:careMoney forKey:@"careMoney"];
    return [dict writeToFile:filePath atomically:YES];
}


- (NSString *)lastSyncCareTime {
    if (_lastSyncCareTime == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"lastSyncCareTime"] == nil) {
            return nil;
        }
        return [dict objectForKey:@"lastSyncCareTime"];
    }
    return _lastSyncCareTime;
}

- (BOOL)setLastSyncCareTimeAndCache:(NSString *)lastSyncCareTime {
    
    _lastSyncCareTime = lastSyncCareTime;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:lastSyncCareTime forKey:@"lastSyncCareTime"];
    return [dict writeToFile:filePath atomically:YES];
}


- (NSString *)deviceSyncTime {

    if (_deviceSyncTime == nil) {
        NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
        if ([dict objectForKey:@"deviceSyncTime"] == nil) {
            return @"2016/12/12 10:58";
        }
        return [dict objectForKey:@"deviceSyncTime"];
    }
    return _deviceSyncTime;
}

- (BOOL)setDeviceSyncTimeAndCache:(NSString *)deviceSyncTime{
    
    _deviceSyncTime = deviceSyncTime;
    NSString *filePath = [CLSeverTool getFilePath:@"userInfo.plist"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
    [dict setObject:deviceSyncTime forKey:@"deviceSyncTime"];
    return [dict writeToFile:filePath atomically:YES];
}

//- (NSString *)deviceSyncTime{
//
//    return @"2016-07-27 17:38";
//}

@end
